"""
函数声明：需要使用关键字def，格式如下所示
def 函数名(参数1，参数2，...，参数n):
"""

# 带返回值的函数
def fib(n):
    fibList = []
    a, b = 0, 1
    i = 0

    while (i < n):
        fibList.append(a)
        a, b = b, a + b
        i += 1
    
    return fibList

# 在Py中，函数也是一个对象
def testFunc():

    print("fib(10) is {}".format(fib(10)))

    # 函数声明会在符号表中放入一个函数名，我们可以把这个函数名当作普通变量
    # 函数名可以赋值给普通变量
    ficClone = fib
    print("ficClone(10) is {}".format(ficClone(10)))

    def greet(name):
        return "Hello, " + str(name)

    greetSomeOne = greet
    print("greetSomeOne('Jack') is {}".format(greetSomeOne('Jack')))

    # 嵌套函数的定义，在函数里在定义函数
    def greetAgain(name):
        def getThing():
            return 'Hello, '

        return getThing() + name

    print("greetAgain('Jack') is {}".format(greetAgain('Jack')))

    # 函数的参数也可以传递函数名
    def call(func):
        name = "Alan"
        return func(name)

    print("call(greetSomeOne) is {}".format(call(greetSomeOne)))

    # 函数也可以返回其他函数，这就很秀
    def composeWithReturn():
        def getMes():
            return '我是函数返回的函数'
        
        return getMes
    
    print("composeWithReturn()() is {}".format(composeWithReturn()()))

testFunc()